import { AppType } from "next/dist/shared/lib/utils";

import { ConfigProvider } from "antd";
import dayjs from "dayjs";
// import zhCN from "antd/locale/zh_CN";
import "../styles/globals.css";
import "antd/dist/reset.css";
import Layout from "../layout";
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
import { useRouter } from "next/router";
import { getToken } from "../utils/token";
import { useEffect } from "react";
import { queryClient } from "../utils/queryClient";
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";
import 'aplayer/dist/APlayer.min.css';
import NewTask from "../components/NewTask";

dayjs.locale("zh-cn");

const MyApp: AppType = ({ Component, pageProps }) => {
  const { route, replace, push } = useRouter();
  const isLogin = !!getToken();
  const isLoginPath = route === "/login";
  useEffect(() => {
    if (isLogin && isLoginPath) replace("/parseTask").then();
    if (!isLogin && !isLoginPath) push("/login").then();
    if (isLogin && route === '/') replace("/parseTask").then()
  }, []);
  return (
    <ConfigProvider>
      <QueryClientProvider client={queryClient}>
        <Layout>
          <Component {...pageProps} />
        </Layout>
        { isLogin && <NewTask />}
      </QueryClientProvider>
    </ConfigProvider>
  );
};

export default MyApp;
